﻿using SlaughterItem.Common.DBContext;
using SlaughterItem.Common.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SlaughterItem.Common.Infrastructures.Repositories
{
    /// <summary>
    /// 基类仓储
    /// </summary>
    /// <typeparam name="T">占位符</typeparam>
    public class BaseRepositoryGet<T> : IBaseRepositoryGet<T> where T : class, new()
    {
        GetEFDBContext db;

        public BaseRepositoryGet(GetEFDBContext db)
        {
            this.db = db;
        }

        /// <summary>
        /// 获取所有数据
        /// </summary>
        /// <returns>所有数据</returns>
        public IQueryable<T> GetAll()
        {
            var list = db.Set<T>();
            return list;
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        public int Add(T t)
        {
            db.Add(t);
            var res = db.SaveChanges();
            return res;
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        public int Update(T t)
        {
            db.Update(t);
            var res = db.SaveChanges();
            return res;
        }
    }
}
